package com.stylefeng.guns.modular.system.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.common.persistence.dao.BillCheckMapper;
import com.stylefeng.guns.common.persistence.dao.TBillMapper;
import com.stylefeng.guns.common.persistence.model.BillCheck;
import com.stylefeng.guns.common.persistence.model.TBill;
import com.stylefeng.guns.modular.system.service.ITBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author stylefeng123
 * @since 2018-03-07
 */
@Service
public class TBillServiceImpl extends ServiceImpl<TBillMapper, TBill> implements ITBillService {

    @Autowired
    TBillMapper tBillMapper;

    @Autowired
    BillCheckMapper billCheckMapper;


    @Override
    public List<Map<String, Object>> selectAccountingList(Page<Map<String, Object>> page, Map param) {
        return tBillMapper.selectAccountingList(page,param);
    }

    @Override
    @Transactional
    public void confirmTBill(String ids, BillCheck bill) {
       // 生成t_bill_check，更新t_bill表的billCheckId
        String[] id_arr= ids.split(",");
        bill.setBillCount(id_arr.length);
        billCheckMapper.insert(bill);
        for(String id:id_arr){
            TBill tb=new TBill();
            tb.setId(Integer.parseInt(id));
            tb.setBillCheckId(bill.getId());
            tBillMapper.updateById(tb);
        }
    }

    @Override
    public List<Map<String, Object>> selectAccountingRecordList(Page<Map<String, Object>> page, Map param) {
        return tBillMapper.selectAccountingRecordList(page,param);
    }

    @Override
    public List<Map<String, Object>> selectAccountingRecordDetailList(Page<Map<String, Object>> page, Map param) {
        return tBillMapper.selectAccountingRecordDetailList(page,param);
    }
}
